<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="../../../common/common-easyui.jspf" %>
<!DOCTYPE html >
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
<body>
<div style="width:500px;padding:30px 60px;">
    <form id="ff" method="post" action="groupPaperController?flag=handRule">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="totalScore" style="width:38%" data-options="label:'试题总分:'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="single" name="single" readonly="readonly" style="width:70%"
                   data-options="label:'单选题:',buttonText:'...',prompt:'请选择单选题'">
            <input class="easyui-textbox" id="singleScore" name="scScore" readonly="readonly" style="width:28%"
                   data-options="label:'总分:'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="multiple" name="multiple" readonly="readonly" style="width:70%"
                   data-options="label:'多选题:',buttonText:'...',prompt:'请选择多选题'">
            <input class="easyui-textbox" id="multipleScore" name="mulScore" readonly="readonly" style="width:28%"
                   data-options="label:'总分:'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="blank" name="blank" readonly="readonly" style="width:70%"
                   data-options="label:'填空题',buttonText:'...',prompt:'请选择填空题'">
            <input class="easyui-textbox" id="blankScore" name="blankScore" readonly="readonly" style="width:28%"
                   data-options="label:'总分:'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="judge" name="judge" readonly="readonly" style="width:70%"
                   data-options="label:'判断题',buttonText:'...',prompt:'请选择判断题'">
            <input class="easyui-textbox" id="judgeScore" name="judgeScore" readonly="readonly" style="width:28%"
                   data-options="label:'总分:'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" id="subjective" name="subjective" readonly="readonly" style="width:70%"
                   data-options="label:'主观题',buttonText:'...',prompt:'请选择主观题'">
            <input class="easyui-textbox" id="subjectiveScore" name="subjectiveScore" readonly="readonly"
                   style="width:28%" data-options="label:'总分:'">
        </div>
    </form>
    <div style="text-align:center;padding:5px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">Submit</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:80px">Clear</a>
    </div>
</div>
<!-- 弹出层 -->
<div id="promptDiv" style="display:none;"></div>

<script>
    //提交表单数据
    function submitForm() {
        $('#ff').form('submit', {
            success: function (result) {
                if (result > 0) {
                    $.messager.alert("提示", "组卷成功", "info");
                }
            }
        });
    }
    //清除表单内容
    function clearForm() {
        $('#ff').form('clear');
    }
    //选题
    $(function () {
        // 设置标签的鼠标样式
        $("span.textbox").find("a").css("cursor", "pointer");

        // 给A标签注册点击事件
        $("span.textbox").find("a").on("click", function () {
            var url = null;
            var index = $(this).index("span>a");

            // 获取当前点击标签对应文本框对象
            var $input = $(this).next().next();

            switch (index) {
                case 0:
                    url = "choiceInfoController?flag=single";
                    break;
                case 1:
                    url = "choiceInfoController?flag=multiple";
                    break;
                case 2:
                    url = "blankInfoController?flag=blank";
                    break;
                case 3:
                    url = "judgeInfoController?flag=judge";
                    break;
                case 4:
                    url = "subjectiveInfoController?flag=subjective";
                    break;
                default:
                    break;
            }
            $("#promptDiv").dialog({
                title: "题型窗口",
                width: '800',
                height: '600',
                modal: true,
                href: url,
                buttons: [{
                    text: "确定",
                    handler: function () {
                        // 获取选择复选框对象
                        var $chks = $("#promptDiv input:checkbox:checked");
                        // 定义json字符串格式
                        var json = "[";
                        // 定义总分
                        var totalScore = 0;
                        // 遍历所有选择的复选框对象
                        $chks.each(function () {
                            var $ck = $(this);
                            // 获取复选框对象vlaue值
                            var value = $ck.val();
                            // 获取分数
                            var score = $ck.next().val();
                            // 计算总分
                            totalScore += parseFloat(score);
                            json += "{\"id\":" + value + ",\"score\":" + score + "},"
                        });
                        json = json.substring(0, json.length - 1);
                        json += "]";

                        // 填充内容
                        var inputName = $input.prop("name");
                        $("#" + inputName).textbox('setValue', json);
                        // 填充总分
                        $("#" + inputName + "Score").textbox('setValue', totalScore);

                        // 关闭模态
                        $('#promptDiv').dialog('close');
                    }
                }]
            });
        });
    });
</script>
</body>
</html>